        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>isInstanceOf&lt;T&gt; class / matcher Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="matcher" data-type="isInstanceOf&amp;lt;T&amp;gt;">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../matcher.html">matcher</a> &rsaquo; <a href="../matcher/isInstanceOf.html">isInstanceOf&lt;T&gt;</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>isInstanceOf&lt;T&gt;</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<p>Returns a matcher that matches if an object is an instance
of <code>type</code> (or a subtype).</p>
<p>As types are not first class objects in Dart we can only
approximate this test by using a generic wrapper class.</p>
<p>For example, to test whether 'bar' is an instance of type
'Foo', we would write:</p>
<pre><span class="i ">expect</span><span class="p ">(</span><span class="i ">bar</span><span class="p ">,</span> <span class="k ">new</span> <span class="i ">isInstanceOf</span><span class="o ">&lt;</span><span class="t ">Foo</span><span class="o ">&gt;</span><span class="p ">(</span><span class="p ">)</span><span class="p ">)</span><span class="p ">;</span></pre>
<p>To get better error message, supply a name when creating the
Type wrapper; e.g.:</p>
<pre><span class="i ">expect</span><span class="p ">(</span><span class="i ">bar</span><span class="p ">,</span> <span class="k ">new</span> <span class="i ">isInstanceOf</span><span class="o ">&lt;</span><span class="t ">Foo</span><span class="o ">&gt;</span><span class="p ">(</span><span class="s si">'Foo'</span><span class="p ">)</span><span class="p ">)</span><span class="p ">;</span></pre>
<p>Note that this does not currently work in dart2js; it will
match any type, and isNot(new isInstanceof&lt;T>()) will always
fail. This is because dart2js currently ignores template type
parameters.</p>
<pre class="source">
class isInstanceOf&lt;T&gt; extends BaseMatcher {
 final String _name;
 const isInstanceOf([name = 'specified type']) : this._name = name;
 bool matches(obj, MatchState matchState) =&gt; obj is T;
 // The description here is lame :-(
 Description describe(Description description) =&gt;
     description.add('an instance of ${_name}');
}
</pre>
</div>
<h3>Extends</h3>
<p>
<span class="type-box"><span class="icon-class"></span><a href="../matcher/BaseMatcher.html">BaseMatcher</a></span>&nbsp;&gt;&nbsp;<span class="type-box"><span class="icon-class"></span><strong>isInstanceOf&lt;T&gt;</strong></span></p>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="isInstanceOf">
<button class="show-code">Code</button>
const <strong>isInstanceOf</strong>([name = 'specified type']) <a class="anchor-link" href="#isInstanceOf"
              title="Permalink to isInstanceOf&lt;T&gt;.isInstanceOf">#</a></h4>
<div class="doc">
<pre class="source">
const isInstanceOf([name = 'specified type']) : this._name = name;
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="describe">
<button class="show-code">Code</button>
<a href="../matcher/Description.html">Description</a> <strong>describe</strong>(<a href="../matcher/Description.html">Description</a> description) <a class="anchor-link" href="#describe"
              title="Permalink to isInstanceOf&lt;T&gt;.describe">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Creates a textual description of a matcher,
by appending to <code>mismatchDescription</code>.</p>
<div class="docs-inherited-from">docs inherited from <a href="../matcher/BaseMatcher.html">BaseMatcher</a> </div></div>
<pre class="source">
Description describe(Description description) =&gt;
   description.add('an instance of ${_name}');
</pre>
</div>
</div>
<div class="method inherited"><h4 id="describeMismatch">
<button class="show-code">Code</button>
<a href="../matcher/Description.html">Description</a> <strong>describeMismatch</strong>(item, <a href="../matcher/Description.html">Description</a> mismatchDescription, <a href="../matcher/MatchState.html">MatchState</a> matchState, bool verbose) <a class="anchor-link" href="#describeMismatch"
              title="Permalink to isInstanceOf&lt;T&gt;.describeMismatch">#</a></h4>
<div class="inherited-from">inherited from <a href="../matcher/BaseMatcher.html">BaseMatcher</a> </div><div class="doc">
<p>Generates a description of the matcher failed for a particular

<span class="param">item</span>, by appending the description to 
<span class="param">mismatchDescription</span>.
It does not check whether the 
<span class="param">item</span> fails the match, as it is
only called after a failed match. There may be additional info
about the mismatch in 
<span class="param">matchState</span>.</p>
<pre class="source">
Description describeMismatch(item, Description mismatchDescription,
                            MatchState matchState, bool verbose) =&gt;
 mismatchDescription.add('was ').addDescriptionOf(item);
</pre>
</div>
</div>
<div class="method"><h4 id="matches">
<button class="show-code">Code</button>
bool <strong>matches</strong>(obj, <a href="../matcher/MatchState.html">MatchState</a> matchState) <a class="anchor-link" href="#matches"
              title="Permalink to isInstanceOf&lt;T&gt;.matches">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Tests the matcher against a given <code>item</code>
and return true if the match succeeds; false otherwise.

<span class="param">matchState</span> may be used to return additional info for
the use of <code>describeMismatch</code>.</p>
<div class="docs-inherited-from">docs inherited from <a href="../matcher/BaseMatcher.html">BaseMatcher</a> </div></div>
<pre class="source">
bool matches(obj, MatchState matchState) =&gt; obj is T;
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
